#include "mix_column.h"
#include "matrix.h"
#include "field.h"

static byte mc_matrix[] = {
	0x02, 0x03, 0x01, 0x01,
	0x01, 0x02, 0x03, 0x01,
	0x01, 0x01, 0x02, 0x03,
	0x03, 0x01, 0x01, 0x02,
};

void mix_column(byte* state)
{
	int col,row;
	byte tmp_src[4], tmp_result[4];
	for(col = 0; col < 4; ++col)
	{
		for(row = 0; row < 4; ++row)
			tmp_src[row] = state[row * 4 + col];
		byte_matrix_mul(mc_matrix, 4, 4, tmp_src, 4, 1, tmp_result, 4, element_add, gf_256_11b_mul);
		for(row = 0; row < 4; ++row)
			state[row * 4 + col] = tmp_result[row];
	}
}
